package com.woniu.houtai.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayCancelOrderMQConfig {


    //死信部分

    //死信部分交换机
    @Bean
    public DirectExchange deadLetterExchange(){
        return new DirectExchange("deadLetterExchange");
    }


    //死信部分队列
    @Bean
    public Queue deadLetterQueue(){
        return new Queue("deadLetterQueue");
    }


    //死信部分交换机和队列的绑定
    @Bean
    public Binding deadLetterBinding(){
        return BindingBuilder.bind(deadLetterQueue())
                .to(deadLetterExchange())
                .with("cancelOrder");
    }


    //正常部分

    //正常部分的交换机
    @Bean
    public DirectExchange normalExchange(){
        return new DirectExchange("normalExchange");
    }


    //正常部分的队列(需要绑定死信交换机,并且不能有消费者,并且指定ttl)
    @Bean
    public Queue normalQueue(){
        return QueueBuilder.durable("normalQueue")
                .deadLetterExchange("deadLetterExchange")
                .deadLetterRoutingKey("cancelOrder")
                .ttl(30*1000)
                .build();
    }


    //正常部分的交换机和队列的绑定
    @Bean
    public Binding normalBinding(){
        return BindingBuilder
                .bind(normalQueue())
                .to(normalExchange())
                .with("delayCancelOrder");
    }



}
